package my2Cents.tools;

import my2Cents.Sandbox;
import my2Cents.Undo;
import net.phys2d.raw.Body;
import net.phys2d.raw.FixedJoint;
import net.phys2d.raw.Joint;

public class NoCollideTool extends AbstractConstraintMaker {
	public NoCollideTool() {
		setName("No Collide");
		setDescription("Click and draw out a line between\n" +
				"two objects to disable collision detection\n" +
				"between them.");
		removeProperty(2);
		removeProperty(2);
		removeProperty(2);
		//removeProperty(2);
		//category = "Modifiers";
		noScreen = true;
	}
	
	protected Joint createConstraint(Body b1, Body b2) {
		if(b1 != null && b2 != null) {
			Sandbox.getUndoList().undo(b1, getName());
			Undo toolUndo = new Undo(b1, getWorld(), getName()) {
				public void performUndo() {
					Body b = (Body) this.getObject();
					if(b.getTempData("nc_pair") != null) {
						Body pair = (Body) b.getTempData("nc_pair");
						b.removeExcludedBody(pair);
					}
				}
			};
			Sandbox.getUndoList().add(toolUndo);
			
			b1.addExcludedBody(b2);
			b1.doOutlineFx();
			b2.doOutlineFx();
			b1.attachTempData("nc_pair", b2);
		}
		return null;
	}
}
